﻿namespace ContextualStateless
{
    public partial class StateMachine< TState, TTrigger, TContext >
    {
        /// <summary>
        /// Represents a state transition when transition guard is fulfilled.
        /// </summary>
        public class StateTransition
        {
            #region Attributes

            /// <summary>
            /// The state transitioned from (source state).
            /// Usually matches current object's state.
            /// </summary>
            public TState Source { get; protected set; }

            /// <summary>
            /// The state transitioned to (transition's destination state).
            /// </summary>
            public TState Destination { get; protected set; }

            /// <summary>
            /// The trigger that caused the transition.
            /// </summary>
            public TTrigger Trigger { get; protected set; }

            #endregion

            /// <summary>
            /// Construct a transition.
            /// </summary>
            /// <param name="source">The state transitioned from.</param>
            /// <param name="destination">The state transitioned to.</param>
            /// <param name="trigger">The trigger that caused the transition.</param>
            public StateTransition( TState source, TState destination, TTrigger trigger )
            {
                Source = source;
                Destination = destination;
                Trigger = trigger;
            }

            // ------------------------------------------------------------------------------------------------------

            /// <summary>
            /// True if the transition is a re-entry, i.e. the identity transition.
            /// </summary>
            public bool IsReentry
            {
                get { return Source.Equals( Destination ); }
            }
        }
    }
}
